import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @author: zlz
 * @date: 2021/9/12 21:58
 * @description:
 * @since: JDK1.8
 */
public class FileChanelDemo2 {
    public static void main(String[] args) throws Exception {
        File file = new File("D://zlz.txt");
        FileInputStream inputStream = new FileInputStream(file);
        FileChannel channel = inputStream.getChannel();
        ByteBuffer buffer = ByteBuffer.allocate((int)file.length());
        channel.read(buffer);
        System.out.println(new String(buffer.array()));
        inputStream.close();
    }
}
